package biz.k11i.gdd2011.board;

public class BytesToIntsPacker {
    public static int[] pack(byte[] bytes) {
        int[] result = new int[(bytes.length + 4) / 5];

        int limit = bytes.length / 5;
        for (int i = 0; i < limit; i++) {
            int index = i * 5;
            result[i] = bytes[index] | (bytes[index + 1] << 6)
                    | (bytes[index + 2] << 12) | (bytes[index + 3] << 18)
                    | (bytes[index + 4] << 24);
        }

        if (limit * 5 < bytes.length) {
            int val = 0;
            int begin = limit * 5;
            for (int i = begin; i < bytes.length; i++) {
                val |= bytes[i] << ((i - begin) * 6);
            }
            result[limit] = val;
        }

        return result;
    }
}
